package com.asialjim.wechat.official.cloud;

import com.asialjim.wechat.official.api.templatemessage.GetAllPrivateTemplateApiResponse;
import com.asialjim.wechat.official.api.templatemessage.GetIndustryApiResponse;
import com.asialjim.wechat.official.api.templatemessage.SetIndustryApiRequest;
import com.asialjim.wechat.official.apiservice.TemplateMessageService;
import com.asialjim.wechat.official.templatemessage.TemplateMessage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: TemplateMessageCloud ]</i></h2><strong>
 * <p> template message cloud
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/3/30   &nbsp;&nbsp; JDK 8
 */
@RestController
@AllArgsConstructor
@RequestMapping("/we_chat/template/message")
public class TemplateMessageCloud {
    private final TemplateMessageService templateMessageService;


    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: apiSetIndustry ]</i></h3>
     * we-chat template message api set industry
     * @param industryInfo {@link SetIndustryApiRequest.BodyParam industry info}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:14
     */
    @PostMapping("/industry/set")
    public boolean apiSetIndustry(String ToUserName,@RequestBody SetIndustryApiRequest.BodyParam industryInfo){
        try {
            templateMessageService.apiSetIndustry(industryInfo);
            return true;
        } catch (Exception e){
            return false;
        }
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: industryInfo ]</i></h3>
     * get template industry
     * @return {@link GetIndustryApiResponse industry info}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:15
     */
    @GetMapping("/industry")
    public GetIndustryApiResponse industryInfo(String ToUserName){
        return templateMessageService.industryInfo();
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: addTemplate ]</i></h3>
     * add template
     * @param templateShortId {@link String template short id}
     * @return {@link String template id for api add template}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:17
     */
    @GetMapping("/template/add")
    public String addTemplate(String ToUserName,String templateShortId){
        return templateMessageService.addTemplate(templateShortId);
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: allPrivateTemplate ]</i></h3>
     * get all private template
     * @return {@link List template list}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:19
     */
    @GetMapping("/template/private/all")
    public List<GetAllPrivateTemplateApiResponse.TemplateInfo> allPrivateTemplate(String ToUserName){
        return templateMessageService.allPrivateTemplate();
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: deletePrivateTemplate ]</i></h3>
     * delete private template by template id
     * @param templateId {@link String template id}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:21
     */
    @GetMapping("/template/private/delete")
    public boolean deletePrivateTemplate(String ToUserName,String templateId){
        try{
            templateMessageService.deletePrivateTemplate(templateId);
            return true;
        } catch (Exception e){
            return false;
        }
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: onceSubscribeTemplateUrl ]</i></h3>
     * once subscribe template url
     * @param scene {@link String desc}
     * @param templateId {@link String desc}
     * @param redirectUrl {@link String desc}
     * @param reserved {@link String desc}
     * @return {@link String once subscribe template url}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:48
     */
    @GetMapping("/subscribe/url")
    public String  onceSubscribeTemplateUrl(String ToUserName, String scene,String templateId,String redirectUrl,String reserved){
        return templateMessageService.onceSubscribeTemplateUrl(scene, templateId, redirectUrl, reserved);
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: sendSubscribeTemplateMessage ]</i></h3>
     * send subscribe template message
     * @param templateMessage {@link TemplateMessage template message}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/15 17:50
     */
    @PostMapping("/send")
    public void sendSubscribeTemplateMessage(@RequestBody TemplateMessage templateMessage){
        templateMessageService.sendSubscribeTemplateMessage(templateMessage);
    }
}
